from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
from MyPro import models
from MyPro.models import User


def index(request):
    return HttpResponse("Hello world!!")

def userList(request):
    list = models.User.objects.all().order_by("id")
    userList = [{"username":"张三","age":25},{"username":"李四","age":26},{"username":"王二","age":27}];
    return render(request,'userList.html',{'userList':list})

def addUser(request):
    models.User.objects.create(username='李四',age=25)
    return HttpResponse("添加成功")

def updateUser(request):
    user = User.objects.get(id=1)
    user.age = 33
    user.save()
    return HttpResponse("更新成功")

def deleteUser(request):
    User.objects.get(id=1).delete()
    return HttpResponse("删除成功")